﻿using Library.Core.Domain.Specification;
using Synthesize.BaseSet.Domain.Aggregation.Entity.Authority;
using System;
using System.Linq.Expressions;

namespace Synthesize.BaseSet.Domain.Specifications.Authority.User
{
    /// <summary>
    /// 用户查询条件拼装
    /// </summary>
    public class GetUserListSpceification : ISpecification<UserInfoEntity>
    {

        private readonly string _name;

        public GetUserListSpceification(string name)
        {
            _name = name;
        }
        public Expression<Func<UserInfoEntity, bool>> SatisfiedBy()
        {
            Specification<UserInfoEntity> spec = new TrueSpecification<UserInfoEntity>();

            if (!string.IsNullOrEmpty(_name))
            {
                spec &= new DirectSpecification<UserInfoEntity>(x => x.UserName.Contains(_name.Trim()) || x.RealName.Contains(_name.Trim()) || x.Telphone.Contains(_name.Trim()));
            }
            return spec.SatisfiedBy();
        }
    }
}
